import React from "react";

import {
  StyleSheet, Text, TouchableOpacity, ViewPropTypes,
} from "react-native";
import PropTypes from "prop-types";

import { Color, FontSize } from "../../common/index";

const Button = props => {
  const {
    disabled, onPress, buttonStyle, textStyle, title, activeOpacity,
  } = props;

  return (
    <TouchableOpacity
      onPress={onPress}
      style={[styles.buttonStyle, buttonStyle]}
      activeOpacity={activeOpacity}
      disabled={disabled}
    >
      <Text style={[styles.textStyle, textStyle, disabled ? styles.disabledStyle : {}]}>{title}</Text>
    </TouchableOpacity>
  );
};

Button.propTypes = {
  onPress: PropTypes.func.isRequired,
  title: PropTypes.string.isRequired,
  textStyle: Text.propTypes.style,
  buttonStyle: ViewPropTypes.style,
  disabled: PropTypes.bool,
  activeOpacity: PropTypes.number,
};
Button.defaultProps = {
  disabled: false,
  textStyle: {},
  buttonStyle: {},
  activeOpacity: 0.8,
};

const styles = StyleSheet.create({
  buttonStyle: {
    borderColor: Color.text_assist,
    borderRadius: 5,
    borderWidth: 0.5,
    paddingHorizontal: 4,
    paddingVertical: 4,
    margin: 2,
    alignItems: "center",
    justifyContent: "center",
    backgroundColor: Color.white,
  },
  textStyle: {
    fontSize: FontSize.SIZE_14,
    color: Color.text_content,
  },
  disabledStyle: {
    opacity: 0.5,
  },
});

export default Button;
